package com.twu.biblioteca.data_structures;

import java.util.ArrayList;

public class Library {
    private ArrayList<Book> bookList;
    private ArrayList<Movie> movieList;
    private ArrayList<User> userList;
    private User activeUser;

    public Library(){
        bookList = new ArrayList<Book>();
        movieList = new ArrayList<Movie>();
        userList = new ArrayList<User>();
    }

    public void add(Book[] books)
    {
        for(Book book : books)
            add(book);
    }

    public void add(Book book){
        bookList.add(book);
    }

    public void add(Movie[] movies)
    {
        for(Movie movie : movies)
            add(movie);
    }

    public void add(Movie movie){
        movieList.add(movie);
    }

    public void add(User[] users)
    {
        for(User user : users)
            add(user);
    }

    public void add(User user){
        userList.add(user);
    }

    public void printBooks() {
        for(Book book : bookList)
            book.print();
    }

    public void printMovies() {
        for(Movie movie : movieList)
            movie.print();
    }

    public String attemptToReserve(String requestedBook) {
        if(canReserve(requestedBook))
            return "Enjoy the book!";
        return "Sorry we don't have that book yet.";
    }

    public boolean canReserve(String requestedBook){
        for(Book book : bookList)
            if(book.isTitle(requestedBook))
                return book.checkOut();
        return false;
    }

    public User getActiveUser() {
        return activeUser;
    }

    public boolean attemptLogin(String username, String password){
        for(User user : userList)
            if(user.loginSuccessful(username, password))
            {
                activeUser=user;
                return true;
            }
        return false;
    }
}
